import 'package:winkai/entity/role_info.dart';
import 'package:winkai/entity/mse_rpy_rsp.dart';
import 'package:winkai/entity/send_msg_rsp.dart';
import 'package:winkai/dio/base_result.dart';
import 'package:winkai/dio/net_utils.dart';
import 'package:winkai/entity/user_info.dart';

class ApiService {
  factory ApiService() {
    _singleton ??= ApiService._();
    return _singleton!;
  }

  static ApiService? _singleton;

  ApiService._();

  Future<BaseResult<UserInfo>> registerAccount(
    String deviceId,
  ) async {
    var result = await NetUtils.instance.requestNetwork<UserInfo>(
        Method.post, '/v1/user/device/register',
        params: {
          "device_id": deviceId,
          "platform": 'wink',
        });
    return result;
  }

  Future<BaseResult<SendMsgRsp>> sendMsg(
    String userId,
    String nickName,
    String characterName,
    String message, {
    String? msgId,
  }) async {
    var result = await NetUtils.instance.requestNetwork<SendMsgRsp>(
        Method.post, '/v1/roleplay/conversation/ask',
        params: {
          "user_id": userId,
          "nick_name": nickName,
          "character_name": characterName,
          "message": message,
          if (msgId?.isNotEmpty == true) "msg_id": msgId,
        });
    return result;
  }

  Future<BaseResult<MsgRpyRsp>> getMsgReply(String msgId) async {
    var result = await NetUtils.instance.requestNetwork<MsgRpyRsp>(
        Method.post, '/v1/roleplay/conversation/answer',
        params: {"msg_id": msgId});
    return result;
  }

  Future<BaseResult<List<RoleInfo>>> getRoleList() async {
    var result = await NetUtils.instance.requestNetwork<List<RoleInfo>>(
        Method.get, '/v1/characters/all',
        queryParameters: {"platform": 'wink'});
    return result;
  }

  Future<List<String>?> getVipBanners() async {
    var result = await NetUtils.instance.requestNetwork<List<String>>(
      Method.get,
      '/v1/subscription/banners',
      queryParameters: {"platform": 'wink'},
    );
    return result.data;
  }
}
